﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using Oxite.Extensions;


namespace ECube.Web.CMS
{
    public class MvcSiteMapNodeModelBinder : IModelBinder
    {
             

        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {

            if (controllerContext.RouteData.Values.ContainsKey("pagePath"))
            {
                string pagePath = controllerContext.RouteData.Values["pagePath"] as String;
                if (pagePath == null)
                {
                    pagePath = "";
                }

                string vPath = "~/" + pagePath;
                return SiteNavigatorService.Current.GetNode(vPath);
              
            }
            return null;
        }
    }
}
